package scu.maqiang.possion;

import scu.maqiang.fes.BVPType;
import scu.maqiang.mesh.Mesh2T3;
import scu.maqiang.mesh.ScalarFunc;
import scu.maqiang.mesh.T3Type;

public class DiscontinuousSource {

	public static void main(String[] args) {

			Mesh2T3 mesh2D = new Mesh2T3().square2D(100, 100, T3Type.Left);
			ScalarFunc ConstCoef = (xyz, relabel, param) -> 1.0e0;
			ScalarFunc sourceFunc = (xyz, label, param) -> {
	        	if (xyz[0] + xyz[1] < 1.0) {
	        		return Math.sin(4 * Math.PI * xyz[0]) * Math.cos(4 * Math.PI * xyz[1]);
	        	}else {
	        		return 0.0;
	        	}
	        };
			Possion2DT31 p = new Possion2DT31(mesh2D);
			p.DirichletProblem(BVPType.COMMON, ConstCoef, null, sourceFunc, null,
					           new int[] {2, 3}, null, null, "MySolutions111.dat");
//			
//	        FES2T31 fs = new FES2T31(mesh2D);
//	        SRMatrix A = new SRMatrix(fs.GetNdof());
	        
	        
//	        GeneralCoefFunc ConstCoef = (xyz, relabel, param) -> 1.0e0;
//	        GeneralCoefFunc[] gcf = {ConstCoef};
//	        fs.assembleHeatStiff(gcf, null, BVPType.COMMON, A);
//	        //fs.assembleHeatStiff(new double[] {1.0}, BVPType.COMMON, A);
////	        System.out.println(A);
////	        System.out.println(A.makeEntrySymmetric());
//	        double[] RHS = new double[fs.GetNdof()];
//	        //GeneralCoefFunc ConstCoef = (xyz, relabel, param) -> 1.0;
//	        GeneralCoefFunc sourceFunc = (xyz, label, param) -> {
//	        	if (xyz[0] + xyz[1] < 1.0) {
//	        		return Math.sin(4 * Math.PI * xyz[0]) * Math.cos(4 * Math.PI * xyz[1]);
//	        	}else {
//	        		return 0.0;
//	        	}
//	        };
//	        gcf[0] = sourceFunc;
//	        fs.assembleHeatSource(gcf, null, BVPType.COMMON, RHS);
//	        A.makeEntrySymmetric();
//	        fs.applyBCZero(A, RHS, Direct.X, BCType.MBN, 2, 3);
//	        
////	        System.out.println(A);
//
////	        IterSSolver solver = new IterSSolver(1.0e-15, 1000000);
////	        
//	        double[] x = new double[fs.GetNdof()];
////	        CSRMatrix mat = new CSRMatrix(A);
////	        solver.PCGSSOR(A, RHS, x, 1.5e0, 1);
////	        Arrays.fill(x, 0.0);
////	        solver.PCGSSOR_2(A, RHS, x, 1.5e0, 1);
//	//
////	        
////	        //System.out.println(A);
////	        
////	        //System.out.println(mat);
////	        
////	        Arrays.fill(x, 0.0);
////	        solver.CG(mat, RHS, x, 1);
////	        
////	        Arrays.fill(x, 0.0);
////	        solver.CG(A, RHS, x, 1);
//	        
//	        Arrays.fill(x, 0.0);
//	        NewIterSSolver newSolver = new NewIterSSolver(A, 1.0e-15, 1000000);
//	        newSolver.PCGSSOR(RHS, x, 1.5e0, 1);
//
//	        Arrays.fill(x, 0.0);
//	        //newSolver.GMRES(RHS, x, 200);
//	        newSolver.GMRES_SSOR(RHS, x, 1.5, 30, 1);
//	        mesh2D.toTecplot("Solutions111.dat", x);
	        
//	        ArrayList<Integer>  li = new ArrayList<Integer>();
//	        li.ensureCapacity(100);
//	        for(int i = 0; i < 100; i++) {
//	        	li.add(null);
//	        }
//	        li.add(1, 2);
//	        System.out.println(li.toString());
	        
//	        Mesh2DT3 mesh6 = mg.square2D(2, 2, T3Type.Left);
//	        mesh6.displayBoundarys();
//	        mesh6.extractBoundarysFromElements();
//	        mesh6.displayBoundarys();
	}

}
